import request from '@/utils/http/uni-ajax';

/** 管理-系统设置枚举 */
const Api = {
  /** 读取设置 */
  Read: '/api/admin/settings/read',
  /** 保存设置 */
  Update: '/api/admin/settings/update',
  /** 获取应用标题 */
  GetAppTitle: '/api/admin/settings/getAppTitle',
  /** 设置应用标题 */
  SetAppTitle: '/api/admin/settings/setAppTitle',
  /** 删除应用标题 */
  DeleteAppTitle: '/api/admin/settings/deleteAppTitle',
  /** 获取应用描述 */
  GetAppDescription: '/api/admin/settings/getAppDescription',
  /** 设置应用描述 */
  SetAppDescription: '/api/admin/settings/setAppDescription',
  /** 删除应用描述 */
  DeleteAppDescription: '/api/admin/settings/deleteAppDescription',
}

/**
 * 读取设置
 * @param root 设置根节点，如投票设置为Votes
 * @param mode 错误消息模型
 */
export function readSettings(root, mode = 'message') {
  return request.get({
    url: Api.Read,
    query: {
      root: root,
    },
    requestOptions: {
      errorMessageMode: mode
    }
  });
}

/**
 * 保存设置
 * @param dto 设置信息
 * @param mode 错误消息模型
 */
export function updateSettings(dto, mode = 'message') {
  return request.post({
    url: Api.Update,
    data: dto,
    requestOptions: {
      errorMessageMode: mode
    }
  });
}

/**
 * 获取应用标题
 * @param mode 错误消息模型
 */
export function getAppTitle(mode = 'message') {
  return request.get({
    url: Api.GetAppTitle,
    requestOptions: {
      errorMessageMode: mode
    }
  });
}

/**
 * 设置应用标题
 * @param title 应用标题
 * @param mode 错误消息模型
 */
export function setAppTitle(title, mode = 'message') {
  return request.post({
    url: Api.SetAppTitle,
    query: {
      title: title,
    },
    requestOptions: {
      errorMessageMode: mode
    }
  });
}

/**
 * 删除应用标题
 * @param mode 错误消息模型
 */
export function deleteAppTitle(mode = 'message') {
  return request.post({
    url: Api.DeleteAppTitle,
    requestOptions: {
      errorMessageMode: mode
    }
  });
}

/**
 * 获取应用描述
 * @param mode 错误消息模型
 */
export function getAppDescription(mode = 'message') {
  return request.get({
    url: Api.GetAppDescription,
    requestOptions: {
      errorMessageMode: mode
    }
  });
}

/**
 * 设置应用描述
 * @param description 应用描述对象
 * @param mode 错误消息模型
 */
export function setAppDescription(description, mode = 'message') {
  return request.post({
    url: Api.SetAppDescription,
    data: dto,
    requestOptions: {
      errorMessageMode: mode
    }
  });
}

/**
 * 删除应用描述
 * @param mode 错误消息模型
 */
export function deleteAppDescription(mode = 'message') {
  return request.post({
    url: Api.DeleteAppDescription,
    requestOptions: {
      errorMessageMode: mode
    }
  });
}